#include "abstractmodelsubject.h"
#include <algorithm>

AbstractModelSubject::AbstractModelSubject()
{
}


void AbstractModelSubject::Register(AbstractModelObserver* observer)
{
    if(find(observers.begin(), observers.end(), observer) == observers.end())
    {
        observers.push_back(observer);
    }
}

void AbstractModelSubject::Unregister(AbstractModelObserver* observer)
{
    vector<AbstractModelObserver*>::iterator itr;
    itr = find(observers.begin(), observers.end(), observer);

    if(itr != observers.end())
    {
        observers.erase(itr);
    }
}

void AbstractModelSubject::NotifyImageUpdated(bool updateHistogram)
{
    AbstractModelObserver* observer;
    for(vector<AbstractModelObserver*>::iterator itr = observers.begin();
        itr != observers.end();
        itr++)
    {
        observer = (*itr);
        observer->OnImageUpdated(updateHistogram);
    }
}
